/*  
     PlAr is Platform Arena: a 2D multiplayer shooting game
     Copyright (C) 2009 Ragagnin Antonio <spocchio@gmail.com>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package plar.elements;

import java.awt.Point;

import plar.core.Common;
import plar.core.Element;
import plar.core.Parameters;
import plar.core.defaultElements.Gun;
import plar.core.defaultElements.Player;
import plar.core.defaultElements.Shoot;

public class GunQueen extends Gun {
	
	public GunQueen(Player player) {
super(player);
		 setProperty("gunName","Queen Gun");
		 setProperty("gunUseAmmo",1);
		 setProperty("lifeTime",500);
	}
	public void fire() {
		if (getAmmo() > (Integer)getProperty("gunUseAmmo") ) {
			setProperty("isFiring", true);
			Shoot shoot = new Shoot();
			shoot.setProperty("owner", this);
			Point shootSpeed = new Point();
			Integer s = (Integer) (getProperty("shootSpeed"));
			Double sdx = (Double) owner.getProperty("directionx");
			Double sdy = (Double) owner.getProperty("directiony");
			if(owner.getSpeed().y!=0) s+=1;
			
			Double d = (Double) (owner.getProperty("direction"));
			if(d<=0.5) d= 0.0; else d=1.0;
			Common.info(" " + s + " " + d);
			Double x = s * sdx;
			Double y = s * sdy;
			shootSpeed.x = x.intValue();
			shootSpeed.y = y.intValue();
			shoot.setProperty("direction", d);
			// shoot.setSpeed(shootSpeed);
			//shoot.setPosition(getShootRelativePosition(shoot.getSize()));
			shoot.setPosition(getShootRelativePosition());
			Parameters p = new Parameters();

			p.put("subAction", "new");
			p.put("persist", true);
			p.put("totalTimes", 1);
			p.put("me", shoot);
			p.put("level", level);
			p.put("speed", shootSpeed);
			shoot.setProperty("lifeTime",getProperty("lifeTime"));
			shoot.level = level;

			// ((ArrayList <Element>)shoot.getProperty("friendlyList")).add(me);
			// ((ArrayList <Element>)me.getProperty("friendlyList")).add(shoot);

			Common.info("firing:" + shootSpeed);
			shoot.actions.runAction("move", p);

			// shoot.setPosition(//new Point(me.getPosition().x+)
			owner.level.AddElement(shoot);
			addAmmo(-(Integer)getProperty("gunUseAmmo") );
		}
	}
}
